/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.uniceub.fsw.util;

import java.lang.reflect.Method;

/**
 * Esta classe possui os métodos usados durante a criação de campos de formularios
 * HTML apartir de um VO.
 * @author Abrahao
 */
public class InputHtml {

    private String type;
    private String name;
    private String size;
    private String maxlength;
    private String className;
    private String javaScript;
    private String titulo;
    
    /**
     * Retorna o nome da classe CSS
     * @return
     */
    public String getClassName() {
        return className;
    }
    /**
     * Retorna o JavaScript
     * @return
     */
    public String getJavaScript() {
        return javaScript;
    }
    /**
     * Retorna o Título sugerido do Input
     * @return
     */
    public String getTitulo() {
        return titulo;
    }
    /**
     * Retorna o atributo MaxLenght do input
     * @return
     */
    public String getMaxlength() {
        return maxlength;
    }
    /**
     * Retorna o atributo Name do input
     * @return
     */
    public String getName() {
        return name;
    }
    /**
     * Retorna o atributo Size do input
     * @return
     */
    public String getSize() {
        return size;
    }
    /**
     * Retorna o atributo Type do input
     * @return
     */
    public String getType() {
        return type;
    }
    /**
     * Define a classe CSS
     * @param className
     */
    public void setClassName(String className) {
        this.className = className;
    }
    /**
     * Define o JavaScript
     * @param javaScript
     */
    public void setJavaScript(String javaScript) {
        this.javaScript = javaScript;
    }
    /**
     * Define o Título do input
     * @param titulo
     */
    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }
    /**
     * Define o atributo MaxLenght do input
     * @param maxlength
     */
    public void setMaxlength(String maxlength) {
        this.maxlength = maxlength;
    }
    /**
     * Define o atributo Name do input
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * Define o atributo Name do input
     * @param size
     */
    public void setSize(String size) {
        this.size = size;
    }
    /**
     * Define o atributo Type do input
     * @param type
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * Com base no tipo de dado, este método retorna todos os atributos necessários
     * para a montagem da tag input em HTML.
     * Recebe como parâmetro o nome do atributo desejado.
     * @param atributo
     * @return inputHtml
     */
    public InputHtml getTipoInput(String atributo) {
        InputHtml input = new InputHtml();
        atributo=Character.toLowerCase(atributo.charAt(0))+atributo.substring(1);
        String[] tiposBanco = {
            "nocep", "cd", "nrcpf", "dt", "dh",
            "ds", "ed", "ee", "id", "lk",
            "mt", "no", "ob", "qt", "sgsexo",
            "sg", "st", "tl", "te", "vl"
        };
        String[] tamanhoInput = {
            "8", "", "11", "10", "19",
            "100", "100", "100", "", "100",
            "", "50", "100", "", "1",
            "2", "1", "15", "100", "8"
        };
        String[] maxLengthInput = {
            "8", "", "11", "10", "19",
            "4096", "100", "100", "", "100",
            "", "50", "4096", "", "1",
            "2", "1", "15", "4096", "8"
        };
        
        String[] tipoInput = {
            "text", "text", "text", "text", "text",
            "textarea", "text", "text", "text", "text",
            "text", "text", "textarea", "text", "radio",
            "text", "text", "text", "textarea", "text"
        };
        String[] classNameInput = {
            "text", "text", "text", "text", "text",
            "textarea", "text", "text", "text", "text",
            "text", "text", "textarea", "text", "text",
            "text", "text", "text", "textarea", "text"
        };

        String[] javaScriptInput = {
          /*CEP*/
            " obrigatorio=\"sim\" onFocus=\"this.className='onfocus';\" onKeyPress=\"mascara(this,cep)\" onBlur=\"this.className='onblur'; destacaObrigatorio(this);\" ",
          /*CODIGO*/
            " onFocus=\"this.className='onfocus';\" onBlur=\"this.className='onblur';\" ",
          /*CPF*/
            " obrigatorio=\"sim\" onFocus=\"this.className='onfocus';\" onKeyPress=\"mascara(this,cpf);\" onBlur=\"validaCPF(this); this.className='onblur'; destacaObrigatorio(this);\" ",
          /*DATA*/
            " obrigatorio=\"sim\" onFocus=\"this.className='onfocus';\" onKeyPress=\"mascara(this,data);\" onBlur=\"validaData(this, this.value); this.className='onblur'; destacaObrigatorio(this); \" ",
          /*DATA E HORA*/            
            " ",
          /*DESCRICAO */
            " onFocus=\"this.className='onfocus';\" onBlur=\"this.className='onblur';\" ",
          /*ENDERECO*/
            " obrigatorio=\"sim\" onFocus=\"this.className='onfocus';\" onBlur=\"this.className='onblur'; destacaObrigatorio(this);\" ",
          /*ENDERECO ELETRONICO*/
            " obrigatorio=\"sim\" onFocus=\"this.className='onfocus';\" onblur=\"validaEmail(this);  this.className='onblur'; destacaObrigatorio(this);\" ",
          /*ID*/
            " ",
          /*LINK*/
            " obrigatorio=\"nao\" onFocus=\"this.className='onfocus';\" onKeyPress=\"mascara(this,site)\" value=\"http://\" onBlur=\"this.className='onblur';\" ",
          /*MATRICULA*/
            " ",
          /*NOME*/
            " obrigatorio=\"sim\" onFocus=\"this.className='onfocus';\" onKeyPress=\"mascara(this,soLetrasEspacos);\"  onblur=\"this.className='onblur';\" destacaObrigatorio(this);\" ",
          /*OBSERVACAO*/
            " onFocus=\"this.className='onfocus';\" onBlur=\"this.className='onblur';\" cols=\"60\" rows=\"4\" ",
          /*QUANTIDADE*/
            " onFocus=\"this.className='onfocus';\" onBlur=\"this.className='onblur';\" ",
          /*SEXO*/
            " ",
          /*SIGLA*/
            " ",
          /*STATUS*/
            " ",
          /*TELEFONE*/
            " obrigatorio=\"sim\" onFocus=\"this.className='onfocus';\" onKeyPress=\"mascara(this,telefone)\" onBlur=\"this.className='onblur'; destacaObrigatorio(this);\" ",
          /*TEXTO*/
            " onFocus=\"this.className='onfocus';\" onBlur=\"this.className='onblur';\" style='height:500px'  ",
          /*VALOR*/
            " onFocus=\"this.className='onfocus';\" onBlur=\"this.className='onblur';\" "
        };

        String[] tituloInput = {
            "CEP", "Código", "CPF", "Data", "Data e Hora",
            "Descrição", "Endereço", "Endereço Eletrônico", "ID", "Link",
            "Matrícula", "Nome", "Observação", "Quantidade", "Sexo",
            "Sigla", "Status", "Telefone", "Texto", "Valor"
        };
        for (int i = 0; i < tiposBanco.length; i++) {
            if (atributo.startsWith(tiposBanco[i])) {
                input.setName(atributo);
                input.setType(tipoInput[i]);
                input.setSize(tamanhoInput[i]);
                input.setMaxlength(maxLengthInput[i]);
                input.setJavaScript(javaScriptInput[i]);
                input.setClassName(classNameInput[i]);
                input.setTitulo(tituloInput[i]);
            }
        }


        return input;
    }
}
